<?php

namespace App;

use DB;
use Illuminate\Database\Eloquent\Model;
use Storage;

/**
 * Class Banner
 *
 * @package App
 * @mixin \Eloquent
 */
class Ztlist extends Model
{
    public $timestamps = false;
    protected $table = 'kl_tag_kind_dic';

    //是否显示
    const DEL_OFF = 1;
    const DEL_ON = 0; 

    static $DelDisplay = [
        self::DEL_OFF => '否',
        self::DEL_ON => '是'
    ];

 
    /**
     * 添加专题
     * @param $request
     * @return array
     */
    static function ZtPublish($request)
    {
        $zhuanti = new Ztlist();

        $zhuanti->name = $request->name;
        if ($request->has('pic_path')) {
            $path = Storage::url(Postings::OssUpdate($request->pic_path));
            $zhuanti->pic_path = $path;
        } else {
            return ['status' => 2, 'message' => '图片呢?'];
        }
		$zhuanti->content = $request->content;
		$zhuanti->title1 = $request->title1;
		$zhuanti->remaker1 = $request->remaker1;
		
		$zhuanti->title2 = $request->title2;
		$zhuanti->remaker2 = $request->remaker2;
		
		$zhuanti->title3 = $request->title3;
		$zhuanti->remaker3 = $request->remaker3;
		
		$zhuanti->title4 = $request->title4;
		$zhuanti->remaker4 = $request->remaker4;
		
		$zhuanti->title5 = $request->title5;
		$zhuanti->remaker5 = $request->remaker5;
		
		$zhuanti->tag_id = $request->tag_id;
		$zhuanti->create_time = date("Y-m-d H:i:s",time());
        if (!$zhuanti->save()) {
            return ['status' => 2, 'message' => '添加失败'];
        }

        return ['status' => 1, 'message' => '添加成功'];
    }


    /**
     * 修改专题
     * @param $request
     * @param $Ztfenlei
     * @return array
     */
    static function ZtfenlieibnModify($request, $Ztlist)
    {

        $Ztlist->name = $request->name;
        if ($request->has('pic_path')) {
            $path = Storage::url(Postings::OssUpdate($request->pic_path));
            $Ztlist->pic_path = $path;
        }
		$Ztlist->content = $request->content;
		$Ztlist->title1 = $request->title1;
		$Ztlist->remaker1 = $request->remaker1;
		
		$Ztlist->title2 = $request->title2;
		$Ztlist->remaker2 = $request->remaker2;
		
		$Ztlist->title3 = $request->title3;
		$Ztlist->remaker3 = $request->remaker3;
		
		$Ztlist->title4 = $request->title4;
		$Ztlist->remaker4 = $request->remaker4;
		
		$Ztlist->title5 = $request->title5;
		$Ztlist->remaker5 = $request->remaker5;
		
		$Ztlist->tag_id = $request->tag_id; 
		

        if (!$Ztlist->save()) {
            return ['status' => 2, 'message' => '修改失败'];
        }

        return ['status' => 1, 'message' => '修改成功'];
    }
	
	//删除专题
    static function Del($id, $request)
    {
        DB::beginTransaction();

        if (!Ztlist::where('id', $id)->update([
            'is_del' => Ztlist::DEL_ON
        ])) {
            DB::rollBack();

            return ['status' => 2, 'message' => '删除失败'];
        }

        DB::commit();

        return ['status' => 1, 'message' => '删除成功'];
    }
	
	//刷新
	static function Shuaxin($id, $request){
		DB::beginTransaction();

        if (!Ztlist::where('id', $id)->update([
            'create_time' => date('Y-m-d H:i:s',time())
        ])) {
            DB::rollBack();

            return ['status' => 2, 'message' => '刷新失败'];
        }

        DB::commit();

        return ['status' => 1, 'message' => '刷新成功'];
	}
}
